import time
from zhipuai import ZhipuAI
from dotenv import load_dotenv, find_dotenv

_ = load_dotenv(find_dotenv())
client = ZhipuAI() # 请填写您自己的APIKey

res = client.videos.generations(
    model="cogvideox",
    prompt="在狂风暴雨中，一个男孩在夜晚的道路上奔跑，天空不时划过闪电，道路中不时有汽车经过。"
)
print(res)

while True:
    response = client.videos.retrieve_videos_result(
        id=f"{res.id}"
    )
    print(response)
    if response.task_status == "PROCESSING":
        print("PROCESSING")
        time.sleep(1)
        continue
    elif response.task_status == "FAIL":
        print("FAIL")
        break
    else:
        print("SUCCESS")
        break